package projectxxx;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.event.*;
import java.util.*;
import com.toedter.calendar.*;
import java.sql.*;
import java.text.SimpleDateFormat;

public class MainWestStockPanel extends JPanel
{
	private JPanel westBaseP=null;
	private Font myFont=null;
	private JLabel mediaStockId=null, mediaTypeName=null, brand=null, 
					barcode=null, serialNo=null, description=null, catId=null,
					title=null, status=null, releaseDate=null, genre=null,
					runTime=null, ageRest=null, director=null, actor1=null,
					actor2=null, dateLastRented=null;
	private JTextField  medStockIdTxt=null, barcodeTxt=null, brandTxt=null,
					serialNoTxt=null, descriptionTxt=null, titleTxt=null,
					runTimeTxt=null, ageRestTxt=null, directorTxt=null,
					actor1Txt=null, actor2Txt=null;
	private Vector genreV=null, mediaTypeV=null, catNameV=null;				
	JComboBox genreJcb=null, mediaTypeJcb=null, catNameJcb=null, statusJcb=null;
	private String myDriver = "com.mysql.jdbc.Driver";
	private	String ipOfDB = "localhost";
	private	MySQLdriverConnection msc=null;
	private	Connection Conn=null;
	JDateChooser lastRentedJdc=null;
	JDateChooser releaseDateJdc=null;
	
	public MainWestStockPanel() 
	{
	
		lastRentedJdc = new JDateChooser();
		releaseDateJdc = new JDateChooser();
		
		myFont = new Font("Arial", Font.BOLD, 10);
		JTextField medStockIdTxt = new JTextField(25);
		medStockIdTxt.setFont(myFont);
		medStockIdTxt.setEditable(false);
		JTextField barcodeTxt = new JTextField(25);
		barcodeTxt.setFont(myFont);
		JTextField brandTxt = new JTextField(25);
		brandTxt.setFont(myFont);
		brandTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		JTextField serialNoTxt = new JTextField(25);
		serialNoTxt.setFont(myFont);
		JTextField descriptionTxt = new JTextField(25);
		descriptionTxt.setFont(myFont);
		JTextField titleTxt = new JTextField(25);
		titleTxt.setFont(myFont);
		titleTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);		
		JTextField runTimeTxt = new JTextField(25);
		runTimeTxt.setFont(myFont);
		runTimeTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);		
		JTextField ageRestTxt = new JTextField(25);
		ageRestTxt.setFont(myFont);
		ageRestTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);				
		JTextField directorTxt = new JTextField(25);
		directorTxt.setFont(myFont);
		directorTxt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		JTextField actor1Txt = new JTextField(25);
		actor1Txt.setFont(myFont);
		actor1Txt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		JTextField actor2Txt = new JTextField(25);
		actor2Txt.setFont(myFont);
		actor2Txt.addKeyListener(
			new KeyAdapter()
			{
				public void keyTyped(KeyEvent e)
				{
					char ch = e.getKeyChar();
					if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch != ' '))
					{
						e.consume();
					}
				}
			}
			);
		
		
		mediaStockId = new JLabel(" Stock ID ");
		mediaTypeName = new JLabel(" Media Type Name ");
		brand = new JLabel(" Brand ");
		barcode = new JLabel(" Barcode ");
		serialNo = new JLabel(" Serial No. ");
		description = new JLabel(" Description ");
		catId = new JLabel(" Category Name ");
		title = new JLabel(" Title ");
		status = new JLabel(" Status ");
		releaseDate = new JLabel(" Release Date");
		genre = new JLabel(" Genre ");
		runTime = new JLabel(" Run Time ");
		ageRest = new JLabel(" Age Restriction ");
		director = new JLabel(" Director ");
		actor1 = new JLabel(" Actor 1 ");
		actor2 = new JLabel(" Actor 2 ");
		dateLastRented = new JLabel(" Date Last Rented ");	
		
		genreV = new Vector();
		genreV.addElement(" Action ");
		genreV.addElement(" Adventure ");
		genreV.addElement(" Animation ");
		genreV.addElement(" Biography ");
		genreV.addElement(" Comedy ");
		genreV.addElement(" Crime ");
		genreV.addElement(" Documentary ");
		genreV.addElement(" Drama ");
		genreV.addElement(" Family ");
		genreV.addElement(" Fantasy ");
		genreV.addElement(" Film-Noir ");
		genreV.addElement(" Game-Show ");
		genreV.addElement(" History ");
		genreV.addElement(" Horror ");
		genreV.addElement(" Music ");
		genreV.addElement(" Musical ");
		genreV.addElement(" Mystery ");
		genreV.addElement(" News ");
		genreV.addElement(" Reality-TV ");
		genreV.addElement(" Romance ");
		genreV.addElement(" Sci-Fi ");
		genreV.addElement(" Short ");
		genreV.addElement(" Sport ");
		genreV.addElement(" Talk-Show ");
		genreV.addElement(" Thriller ");
		genreV.addElement(" War ");
		genreV.addElement(" Western ");
		
		genreJcb = new JComboBox(genreV);
		
		try
		{
			msc = new MySQLdriverConnection("","",ipOfDB,"turtledata");
			Conn = msc.getConnection();
		}
		catch(SQLException sqlE)
		{
			sqlE.printStackTrace();
		}	
		catch(ClassNotFoundException cnfe)
		{
			cnfe.printStackTrace();
		}
		
		mediaTypeV = new Vector();
		
		try
		{
			Statement popMediaVectStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			ResultSet mediaVectRS;
			String stockTypeTableQuery = "SELECT stockTypeName FROM stockTypeTable";
			mediaVectRS = popMediaVectStmt.executeQuery(stockTypeTableQuery);
			String tempSTR;
			mediaVectRS.last();
			int rows = mediaVectRS.getRow();
			mediaVectRS.first();
			mediaTypeV = new Vector();
			for(int i = 1;i <= rows;i++ )
			{
				tempSTR = mediaVectRS.getString(1);
				
				System.out.println(""+tempSTR);
				mediaTypeV.addElement(tempSTR);
				
				mediaVectRS.next();
			}
		}
		catch(SQLException sqlE)
		{
			System.out.println("No problemo");
			sqlE.printStackTrace();
		}//end catch
		
		mediaTypeJcb = new JComboBox(mediaTypeV); 
		
		catNameV = new Vector();
		
		try
		{
			Statement popCatNameVectStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
			ResultSet catNameRS;
			String priceCatTableQuery = "SELECT catName FROM pricecattable";
			catNameRS = popCatNameVectStmt.executeQuery(priceCatTableQuery);
			String tempSTR;
			catNameRS.last();
			int rows = catNameRS.getRow();
			catNameRS.first();
			catNameV = new Vector();
			for(int i = 1;i <= rows;i++ )
			{
				tempSTR = catNameRS.getString(1);
				
				System.out.println(""+tempSTR);
				catNameV.addElement(tempSTR);
				
				catNameRS.next();
			}
		}
		catch(SQLException sqlE)
		{
			System.out.println("No problemo");
			sqlE.printStackTrace();
		}//end catch
		
		catNameJcb = new JComboBox(catNameV); 
		
		Vector statusV = new Vector();
		statusV.addElement(" In ");	
		statusV.addElement(" Out ");
		statusV.addElement(" Damaged ");
		statusV.addElement(" Unavailable ");
		
		statusJcb = new JComboBox(statusV);
		
		westBaseP = new JPanel();
		GroupLayout layout  = new GroupLayout(westBaseP);
		layout.setAutoCreateContainerGaps(true);
		layout.setAutoCreateGaps(true);
		westBaseP.setLayout(layout);
		GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
		
		vGroup.addGroup(layout.createParallelGroup().
        addComponent(mediaStockId).addComponent(mediaTypeName).
        addComponent(title).addComponent(status).
        addComponent(barcode).addComponent(brand).
        addComponent(serialNo).addComponent(description).
        addComponent(catId).addComponent(runTime).
        addComponent(releaseDate).addComponent(genre).
        addComponent(ageRest).addComponent(serialNo).
        addComponent(director).addComponent(actor1).
        addComponent(actor2).addComponent(dateLastRented));
  	    vGroup.addGroup(layout.createParallelGroup().
        addComponent(medStockIdTxt).addComponent(mediaTypeJcb).
        addComponent(titleTxt).addComponent(statusJcb).
        addComponent(barcodeTxt).addComponent(brandTxt).
        addComponent(serialNoTxt).addComponent(descriptionTxt).
        addComponent(catNameJcb).addComponent(runTimeTxt).
        addComponent(releaseDateJdc).addComponent(genreJcb).
        addComponent(ageRestTxt).addComponent(serialNoTxt).
        addComponent(directorTxt).addComponent(actor1Txt).
        addComponent(actor2Txt).addComponent(lastRentedJdc));
   		layout.setHorizontalGroup(vGroup);
   		
   		GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
		hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(mediaStockId).addComponent(medStockIdTxt));
   		hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(mediaTypeName).addComponent(mediaTypeJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(title).addComponent(titleTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(status).addComponent(statusJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(barcode).addComponent(barcodeTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(brand).addComponent(brandTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(serialNo).addComponent(serialNoTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(description).addComponent(descriptionTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(catId).addComponent(catNameJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(runTime).addComponent(runTimeTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(releaseDate).addComponent(releaseDateJdc));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(genre).addComponent(genreJcb));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(ageRest).addComponent(ageRestTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(director).addComponent(directorTxt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(actor1).addComponent(actor1Txt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(actor2).addComponent(actor2Txt));
        hGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE,true).
        addComponent(dateLastRented).addComponent(lastRentedJdc));
        layout.setVerticalGroup(hGroup);
        
        //setup "this" Jpanel
		this.setLayout(new GridLayout(1,1));
		this.add(westBaseP);
	}//end of MainWestStockPanel
		
	public java.util.Date getReleaseDate()
	{
		return releaseDateJdc.getDate();
	}	
	public java.util.Date getRentedDate()
	{
		return lastRentedJdc.getDate();
	}
}//end of MainWestStockPanel class
